<html>
<head><meta charset="utf-8"><title>IndexVec PhantomData · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/IndexVec.20PhantomData.html">IndexVec PhantomData</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217365080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/IndexVec%20PhantomData/near/217365080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/IndexVec.20PhantomData.html#217365080">(Nov 20 2020 at 05:51)</a>:</h4>
<p>Is the use of <code>PhantomData</code> in <code>IndexVec</code> only to create a use of the generic parameter <code>I</code>, or is it taking advantage of variance properties too?</p>
<div class="codehilite"><pre><span></span><code>pub trait Idx: Copy + &#39;static + Ord + Debug + Hash {
    ...
}

#[derive(Clone, PartialEq, Eq, Hash)]
pub struct IndexVec&lt;I: Idx, T&gt; {
    pub raw: Vec&lt;T&gt;,
    _marker: PhantomData&lt;fn(&amp;I)&gt;,
}

pub struct IntoIdx&lt;I: Idx&gt; {
    _marker: PhantomData&lt;fn(&amp;I)&gt;,
}
</code></pre></div>
<p>I'm still trying to wrap my head around variance concepts, and I'm having trouble figuring out what relationship this establishes between different <code>IndexVec</code> types. Is the choice of <code>PhantomData&lt;fn(&amp;I)&gt;</code> appropriate? I read that as "contravariant with respect to <code>&amp;I</code>", which already kind of confuses me, TBH.</p>



<a name="217365320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/IndexVec%20PhantomData/near/217365320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/IndexVec.20PhantomData.html#217365320">(Nov 20 2020 at 05:57)</a>:</h4>
<p>Not to answer your question directly, but I found this helpful: <a href="https://users.rust-lang.org/t/looking-for-a-deeper-understanding-of-phantomdata/32477">https://users.rust-lang.org/t/looking-for-a-deeper-understanding-of-phantomdata/32477</a></p>



<a name="217365769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/IndexVec%20PhantomData/near/217365769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/IndexVec.20PhantomData.html#217365769">(Nov 20 2020 at 06:08)</a>:</h4>
<p>Thanks, I'll give that a read</p>



<a name="217365803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/IndexVec%20PhantomData/near/217365803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/IndexVec.20PhantomData.html#217365803">(Nov 20 2020 at 06:09)</a>:</h4>
<p>Take your time <span aria-label="joy" class="emoji emoji-1f602" role="img" title="joy">:joy:</span></p>



<a name="217365866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/IndexVec%20PhantomData/near/217365866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/IndexVec.20PhantomData.html#217365866">(Nov 20 2020 at 06:11)</a>:</h4>
<p>Lol, tbh, I skimmed it earlier today and thought I should come back to it after a good night's sleep</p>



<a name="217365872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/IndexVec%20PhantomData/near/217365872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/IndexVec.20PhantomData.html#217365872">(Nov 20 2020 at 06:11)</a>:</h4>
<p>It's long</p>



<a name="217365876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/IndexVec%20PhantomData/near/217365876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/IndexVec.20PhantomData.html#217365876">(Nov 20 2020 at 06:11)</a>:</h4>
<p>and detailed</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>